<template>
  <BasicTable @register="registerTable" :row-selection="selectMethods?.rowSelection">
    <template #tableTitle>
      <a-button-group>
        <template v-if="showAddBtn">
          <a-button
            type="primary"
            v-auth="addauth"
            preIcon="ant-design:plus-outlined"
            @click="method.handleCreate"
          >
            {{ addtitle }}
          </a-button>
        </template>
        <template v-if="importBtn?.showbtn">
          <a-button
            type="default"
            v-auth="importBtn?.auth"
            :preIcon="importBtn.icon ?? 'ant-design:import-outlined'"
            >{{ importBtn.title ?? '导入' }}}</a-button
          >
        </template>
        <template v-if="exportBtn?.showbtn">
          <a-button
            type="default"
            v-auth="exportBtn?.auth"
            :preIcon="exportBtn.icon ?? 'ant-design:export-outlined'"
            >{{ exportBtn.title ?? '导出' }}}</a-button
          >
        </template>

        <template v-if="batchDelBtn?.showbtn">
          <a-button type="default" v-auth="batchDelBtn?.auth" @click="method.batchDelete">{{
            batchDelBtn.title ?? '批量删除'
          }}</a-button>
        </template>
      </a-button-group>
      <slot name="extendTableTitle"></slot>
    </template>
    <template #toolbar>
      <slot name="extendToolbar"></slot>
    </template>
    <template #bodyCell="data">
      <template v-if="data.column?.key == 'action'">
        <TableAction :actions="method.getTableAction(data.record)" />
      </template>
      <slot name="column" v-bind="data || {}"></slot>
    </template>
  </BasicTable>
</template>
<script setup lang="ts">
  import { BasicTable, TableAction, TableActionType } from '/@/components/Table';
  import { propTypes } from '/@/utils/propTypes';
  import { PropType } from 'vue';
  import { IRowSelection } from '@/hooks/system/useListPage';
  import { ButtonGroup as AButtonGroup } from 'ant-design-vue';

  interface IListTableParam {
    title?: string;
    auth?: string;
    showbtn?: boolean;
    icon?: string;
  }

  defineProps({
    method: propTypes.object,
    registerTable: Function as PropType<(instance: TableActionType, formInstance: any) => any>,
    addtitle: propTypes.string.def('新增'),
    addauth: propTypes.string.def(''),
    showAddBtn: propTypes.bool.def(true),
    selectMethods: Object as PropType<IRowSelection>,
    batchDelBtn: {
      type: Object as PropType<IListTableParam>,
      default: () => ({ title: '批量删除', auth: '', showbtn: false }),
    },
    importBtn: {
      type: Object as PropType<IListTableParam>,
      default: () => ({ title: '导入', auth: '', showbtn: false }),
    },
    exportBtn: {
      type: Object as PropType<IListTableParam>,
      default: () => ({ title: '导出', auth: '', showbtn: false }),
    },
  });
</script>
